<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>xxx</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/customer.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        .aui-tab-item {
            font-size: 0.8rem;
        }
    </style>
</head>

<body>
<div class="aui-tab" id="tab">
    <div class="aui-tab-item aui-active">使用技巧</div>
    <div class="aui-tab-item">
        <div></div>政策解读</div>
    <div class="aui-tab-item">通知公告</div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script>
    apiready = function() {
        var tab = new auiTab({
            element: document.getElementById("tab"),
        }, function(ret) {
            // console.log(JSON.stringify(ret));
            // 点击tab，切换framegroup到对应的页面
            api.setFrameGroupIndex({
                name: 'frame1_find_group',
                index: ret.index - 1,
                scroll: true, //是否带动画效果
                reload: true
            });
        });
        
        // 2019-6-21 17:02:11 业务使用，本文章内容用不到此处。
        // 监听底部按钮切换
        api.addEventListener({
            name: 'indexChangeEvent'
        }, function(ret, err) {
            if (ret) {
                //  alert( JSON.stringify( ret ) );
                if (ret.value.index == 1) { //底部导航切换到“发现”
                    fnOpenFindFrameGroup();
                } else {
                    fnCloseFindFrameGroup();
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
        
        // 左右滚动framegroup时，监听并执行回调
        api.addEventListener({
            name: 'frameGroupChangeEvent'
        }, function(ret, err) {
            if (ret) {
                //  alert( JSON.stringify( ret ) );
                // console.log("framegroup当前index:" + ret.value.id);
                tab.setActive(ret.value.id + 1);
                
            } else {
                alert(JSON.stringify(err));
            }
        });
        
    }
    
    // 打开页面组，实现左右滑动切换效果
    function fnOpenFindFrameGroup() {
        // 计算y坐标
        var tabHeight = $api.offset($api.dom('#tab')).h; //tab切换栏高度
        var indexHtmlHeaderHeight = $api.getStorage('indexHtmlHeaderHeight'); //顶部标题栏高度
        var y = parseInt(tabHeight)+parseInt(indexHtmlHeaderHeight);
        
        api.openFrameGroup({
            name: 'frame1_find_group',
            scrollEnabled: true,
            rect: {
                x: 0,
                y: y,
                w: 'auto',
                h: api.frameHeight-parseInt(tabHeight)
            },
            index: 0,
            frames: [{
                name: 'frame1_1skill',
                url: 'frame1_1skill.html',
                bgColor: '#fff'
            }, {
                name: 'frame1_2policy',
                url: 'frame1_2policy.html',
                bgColor: '#fff'
            }, {
                name: 'frame1_3notice',
                url: 'frame1_3notice.html',
                bgColor: '#fff'
            }]
        }, function(ret, err) {
            if (ret) {
                api.sendEvent({
                    name: 'frameGroupChangeEvent',
                    extra: {
                        id: ret.index
                    }
                });
            }
        });
    }
</script>

</html>